<?php
	namespace Home\Controller;
	// use Think\Controller;
	class IndexController extends HomeController
	{
	    public function index()
	    {
	    	// 广告
	    	$a=M('ad')->order('id desc')->find();
	    	$this->assign('v',$a);

	    	// 轮播图
	    	$lunbo = M('lunbo');
	        $lis = $lunbo->select();
	       	$this->assign('lis',$lis);
	        // 公告
	        $notice = M('notice');
	    	$gg = $notice->select();
	    	$cgg = $notice->count();
	    	$this->assign('gg',$gg);
	    	$this->assign('cgg',$cgg);
	    	// 首页 
	    	$module = M('module')->select();
	    	$mk = M('mbook')->select();

	    	// var_dump($mk);

	    	$this->assign('module',$module);
	    	$this->assign('mbook',$mk);
	    	
	        $this->display();
	    }

	     public function coteajax(){
			include "./gaimi/SendTemplateSMS.php";
			$result = rand(1000,9999);

			sendTemplateSMS(I('phone') ,array($result,'2'),"1");	

			cookie('yanzheng',$result,120); 

			$this->ajaxreturn($result);
		}

		public function verify()
		{
			$user = M('user');

			// var_dump($user);
			$user->password = I('newpassword');
			// 要修改的用户的id
			$id = $_SESSION['home_user']['id'];

			$pwd = $user->where("id = $id")->find();
			
			// var_dump($_COOKIE['yanzheng']);
			if(I('oldpassword') == I('newpassword')){

				$result = '两次密码不能相同';
			}elseif(I('yanzheng') != $_COOKIE['yanzheng']){
				$result = '验证码不相同哦';	
			}elseif(I('oldpassword') != $pwd['password']){
				$result = '旧密码输入错误哦O.o';	
			}else{
				
				$gai = M('user');
				$gai->password = I('newpassword');

				// 要修改的用户的id
				$id = $_SESSION['home_user']['id'];
				$gai->where("id = $id")->save();
				$result = '密码修改成功';
			}
			$this->ajaxreturn($result);
		}
	}